package com.sale.succ.datacomp.region;

import com.sale.succ.forms.ClientForm;
import com.sale.succ.objects.Session;

import eve.fx.Point;
import eve.ui.table.TableControl;

public class RegionTable extends TableControl {
	private RegionTableModel regionModel;

	public RegionTable() {
		setTableModel(getRegionModel());
		allowDragSelection = false;
		multiSelect = false;
	}

	public int getPrefHeight() {
		int rowh = getRegionModel().calculateRowHeight(0);
		int rowCount = getRegionModel().itemCount();
		return rowh * rowCount;
	}

	private RegionTableModel getRegionModel() {
		if (regionModel == null) {
			regionModel = new RegionTableModel();
		}
		return regionModel;
	}

	public boolean canSelect(int row, int col) {
		if (row == -1)
			return false;
		return true;
	}

	public void penClicked(Point p) {
		int line = getSelectedLine();

		if (line == -1) {
			return;
		}

		String groupId = getRegionModel().getGroupId(line);
		Session.getInstance().setGroupId(groupId);
		Session.getInstance().addGrClient(groupId);
		new ClientForm().execute();
	}
}
